﻿using GN.Pay.Client.Request.Trade;
using GN.Pay.Client.Response.Trade;
using GN.Pay.Client.Services;
using GN.Pay.Client.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GN.Pay.Client.Extensions
{
    /// <summary>
    /// 支付申请服务扩展
    /// </summary>
    public static class TradePayApplyServiceExtensions
    {
        /// <summary>
        /// 异步查询支付申请
        /// </summary>
        /// <param name="service"></param>
        /// <param name="applyId"></param>
        /// <returns></returns>
        public static async Task<PayApplyResponse> QueryPayApplyAsync(this ITradeQueryService service, string applyId)
        {
            ExceptionUtils.CheckNotNull(service, nameof(service));
            ExceptionUtils.CheckNotNullOrNotWhiteSpace(applyId, nameof(applyId));
            return await Task.Run<PayApplyResponse>(() =>
            {
                return service.QueryPayApply(applyId);
            });
        }

        /// <summary>
        /// 异步支付申请注册
        /// </summary>
        /// <param name="service"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        public static async Task<PayApplyResponse> PayApplyRegister(this ITradeApplyService service, PayApplyRequest request)
        {
            ExceptionUtils.CheckNotNull(service, nameof(service));
            ExceptionUtils.CheckNotNull(request, nameof(request));
            return await Task.Run<PayApplyResponse>(() =>
            {
                return service.PayApplyRegister(request);
            });
        }

        /// <summary>
        /// 异步支付通道注册
        /// </summary>
        /// <param name="service"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        public static async Task<PayChannelResponse> PayChannelRegister(this ITradeApplyService service, PayChannelRequest request)
        {
            ExceptionUtils.CheckNotNull(service, nameof(service));
            ExceptionUtils.CheckNotNull(request, nameof(request));
            return await Task.Run<PayChannelResponse>(() =>
            {
                return service.PayChannelRegister(request);
            });
        }

        /// <summary>
        /// 异步支付申请与通道注册
        /// </summary>
        /// <param name="service"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        public static async Task<PayChannelResponse> PayApplyAndChannelRegister(this ITradeApplyService service, PayApplyAndChannelRequest request)
        {
            ExceptionUtils.CheckNotNull(service, nameof(service));
            ExceptionUtils.CheckNotNull(request, nameof(request));
            return await Task.Run<PayChannelResponse>(() =>
            {
                return service.PayApplyAndChannelRegister(request);
            });
        }
    }
}
